package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import entities.Process;
import factory.DBConnectionFactory;

public class MYSQLProcessDAO extends ProcessDAO{

	@Override
	public ArrayList<Process> getProcess() {
		ArrayList<Process> ps = new ArrayList<Process>();
		Process p;
	    DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
	    Connection conn = myFactory.getConnection();
	    PreparedStatement pstmt3;
		try {
			pstmt3 = conn.prepareStatement("SELECT * FROM [Process$]");
	        ResultSet rs = pstmt3.executeQuery();
	        while(rs.next()){
	        	p=new Process();
	        	p.setProcessID(rs.getInt(1));
	        	p.setCreationTime(rs.getInt(2));
	        	p.setMemorySize(rs.getInt(3));
	        	p.setPriority(rs.getInt(4));
	        	p.setType(rs.getString(5));
	        	ps.add(p);
	        }
	        	
		} catch (SQLException ex) {
			// TODO Auto-generated catch block
			 Logger.getLogger(MYSQLProcessDAO.class.getName()).log(Level.SEVERE, null, ex);
		}
		return ps;
	}

	@Override
	public String[] getProcessCol() {
		// TODO Auto-generated method stub
		String[] s = {"Process ID", "Creation Time", "MemorySize", "Priority", "Type"};
		return s;
	}

}
